package com.crm.dao;

import java.util.List;

import org.springframework.orm.hibernate5.support.HibernateDaoSupport;

import com.crm.entity.Visitor;

public class VisitorDao extends HibernateDaoSupport {

	public void addVisitor(Visitor visitor) {
			this.getHibernateTemplate().save(visitor);
	}

	public List<Visitor> findAllVisitor() {
		return (List<Visitor>) this.getHibernateTemplate().find("from Visitor");
	}

	public Visitor findVisitorById(Visitor visitor) {
		List<Visitor> find = (List<Visitor>) this.getHibernateTemplate().find("from Visitor where vid = ?", visitor.getVid());
		if(find!=null&&find.size()!=0){
			return find.get(0);
		}
		return null;
	}

	public void deleteVisitor(Visitor findVisitor) {
		this.getHibernateTemplate().delete(findVisitor);
	}

	public void updateVisitor(Visitor visitor) {
		this.getHibernateTemplate().update(visitor);
	}

}
